package com.satchi.struts.action.customeraction;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.satchi.hib.pojo.FinCustomer;
import com.satchi.service.GetCustomerService;
import com.satchi.struts.ActionHelper;
import com.satchi.struts.form.FinCustomerForm;

public class CustomeraddAction extends Action {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		FinCustomerForm fcf =(FinCustomerForm)form;
		FinCustomer fc = new FinCustomer();
		fc.setCustomerid(fcf.getCustomerId());
		fc.setCustomer(fcf.getCustomer());
		fc.setCustomerremark(fcf.getCustomerRemark());
		fc.setIsenable(true);

		GetCustomerService customerServ = new GetCustomerService();
		String parentId = fcf.getParentCustomer();
		FinCustomer parentCustomer = customerServ.get(parentId);
		fc.setParent(parentCustomer);
		
		customerServ.save(fc);
		return mapping.findForward(ActionHelper.SUCCESS);
	}
	
}
